package elements.labels; 

import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.events.Event;
import flash.text.TextFieldAutoSize;
import string.Css;


class BaseLabel extends Sprite {
	
	public var text:String;
	var css:Css;
	public var style:String;
	var _height:Float;
	
	public function new()	{super();}
	
	function build( text:String ):Void {
		
		var title:TextField = new TextField();
		title.x = 0;
		title.y = 0;
		
		this.text = text;
		
		title.htmlText = this.text;
		
		var format:TextFormat = new TextFormat();
		format.color = this.css.color;
		//format.font = "Verdana";
		// format.font = this.css.font_family?this.css.font_family:'Verdana';
		format.font = if (this.css.font_family != null) this.css.font_family else 'Verdana';
		format.bold = this.css.font_weight == 'bold';
		format.size = this.css.font_size;
		format.align = flash.text.TextFormatAlign.CENTER; //"center";
	
		title.setTextFormat(format);
		title.autoSize = flash.text.TextFieldAutoSize.LEFT; //"left";
		
		title.y = this.css.padding_top+this.css.margin_top;
		title.x = this.css.padding_left+this.css.margin_left;
		
		//title.border = true;
		
		if ( this.css.background_colour_set )
		{
			this.graphics.beginFill( this.css.background_colour, 1);
			this.graphics.drawRect(0,0,this.css.padding_left + title.width + this.css.padding_right, this.css.padding_top + title.height + this.css.padding_bottom );
			this.graphics.endFill();
		}

		this.addChild(title);
	}
	
	public function get_width():Float {
		return this.getChildAt(0).width;
	}
	
	public function die(): Void {
		
		this.graphics.clear();
		while ( this.numChildren > 0 )
			this.removeChildAt(0);
	}
}
